package gases.as3.librarys.compnents.ui.basic
{
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import gases.as3.librarys.compnents.ui.GUIComepments;
	
	public class GLabel extends GUIComepments
	{
		public function GLabel(txt:String, color:uint = 0x000000, size:int = 12, w:int = Number.NaN,  h:int = Number.NaN)
		{
			_txt = txt;
			_color = color;
			_size = size;
			_width = w;
			_height = h;
			super();
		}
		
		override protected function initialization():void
		{
			super.initialization();
			_text = new TextField();
			_text.mouseEnabled = false;
			_text.selectable = false;
			resetLabel();
		}
		
		private function resetLabel():void
		{
			if(!_format)
			{
				_format = new TextFormat();
				_format.color = _color;
				_format.size = _size;
				_format.leftMargin = 1;
				_format.leading = 1;
				_format.align =  TextFieldAutoSize.LEFT;
				_format.letterSpacing =  1;
			}
			
			_text.defaultTextFormat = _format;
			_text.multiline = false;
			_text.wordWrap = false;
			_text.text = _txt;
			addChild(_text);
			resetWH();
		}

		public function get format():TextFormat
		{
			return _format;
		}
		
		public function setFormat(mat:TextFormat, start:int = -1 , end:int = -1):void
		{
			_format = mat;
			_text.setTextFormat(_format, start, end);
			_text.defaultTextFormat = _format;
			resetWH();
		}
		
		public function set color(value:uint):void
		{
			_color = value;
			_format.color = value;
			setFormat(_format);
		}
		
		public function set text(str:String):void
		{
			_text.text = str;
			_txt = str;
			resetWH();
		}
		
		public function get text():String
		{
			return _txt;
		}
		
		private function resetWH():void
		{
			if(_width)
			{
				_text.width = _width;
				_text.multiline = true;
				_text.wordWrap = true;
			}
			if(_height)
			{
				_text.height = _height;
			}
			else
			{
				_text.width = _text.textWidth + 4;
				_text.height = _text.textHeight + 5;
			}
		}
		
		override public function dispose():void
		{
			this.removeChild(_text);
			_text = null;
			_format = null;
			super.dispose();
		}
		
		private var _text:TextField;
		private var _format:TextFormat;
		private var _color:uint = 0x000000;
		private var _size:int = 12;
		private var _txt:String;
		private var _width:int;
		private var _height:int;
	}
}


